package org.pearl.validation.demo.service.impl;

import org.pearl.validation.demo.pojo.dto.UserInfoDTO;
import org.pearl.validation.demo.pojo.entity.User;
import org.pearl.validation.demo.dao.UserMapper;
import org.pearl.validation.demo.pojo.po.UserInfoPO;
import org.pearl.validation.demo.pojo.query.UserInfoDbQuery;
import org.pearl.validation.demo.pojo.query.UserInfoServiceQuery;
import org.pearl.validation.demo.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author td
 * @since 2021-05-29
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Autowired
    UserMapper userMapper;

    @Override
    public UserInfoDTO getUserInfo(UserInfoServiceQuery userInfoServiceQuery) {
        // 查询对象转换 userInfoServiceQuery=》userInfoDbQuery
        UserInfoDbQuery userInfoDbQuery=new UserInfoDbQuery();
        BeanUtils.copyProperties(userInfoServiceQuery,userInfoDbQuery);

        // 返回结果集转换 userInfoPO=》userInfoDTO
        UserInfoPO userInfoPO = userMapper.getUserInfo(userInfoDbQuery);
        UserInfoDTO userInfoDTO=new UserInfoDTO();
        BeanUtils.copyProperties(userInfoPO,userInfoDTO);

        return userInfoDTO;
    }
}
